<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><title>深入JavaScript的运行原理 | Justic</title><meta name="keywords" content="JavaScript"><meta name="author" content="Justic"><meta name="copyright" content="Justic"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="1、深入V8引擎原理1.1 JavaScript代码的执行JavaScript代码下载好之后，是如何一步步被执行的呢？ 我们知道，浏览器内核是由两部分组成的，以webkit为例：  WebCore：负责解析HTML解析、布局、渲染等等相关的工作 JavaScriptCore：解析、执行JavaScript代码   另外一个强大的JavaScript引擎就是V8引擎 1.2 V8引擎的执行原理 我们">
<meta property="og:type" content="article">
<meta property="og:title" content="深入JavaScript的运行原理">
<meta property="og:url" content="http://example.com/2022/07/27/JavaScript/%E6%B7%B1%E5%85%A5JavaScript%E7%9A%84%E8%BF%90%E8%A1%8C%E5%8E%9F%E7%90%86/index/index.html">
<meta property="og:site_name" content="Justic">
<meta property="og:description" content="1、深入V8引擎原理1.1 JavaScript代码的执行JavaScript代码下载好之后，是如何一步步被执行的呢？ 我们知道，浏览器内核是由两部分组成的，以webkit为例：  WebCore：负责解析HTML解析、布局、渲染等等相关的工作 JavaScriptCore：解析、执行JavaScript代码   另外一个强大的JavaScript引擎就是V8引擎 1.2 V8引擎的执行原理 我们">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://dogefs.s3.ladydaily.com/~/source/wallhaven/full/z8/wallhaven-z82evv.jpg">
<meta property="article:published_time" content="2022-07-27T12:54:33.000Z">
<meta property="article:modified_time" content="2022-08-08T03:23:05.522Z">
<meta property="article:author" content="Justic">
<meta property="article:tag" content="JavaScript">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://dogefs.s3.ladydaily.com/~/source/wallhaven/full/z8/wallhaven-z82evv.jpg"><link rel="shortcut icon" href="/img/favicon.png"><link rel="canonical" href="http://example.com/2022/07/27/JavaScript/%E6%B7%B1%E5%85%A5JavaScript%E7%9A%84%E8%BF%90%E8%A1%8C%E5%8E%9F%E7%90%86/index/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"/search.xml","preload":false,"languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: true,
  isAnchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: '深入JavaScript的运行原理',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2022-08-08 11:23:05'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><!-- hexo injector head_end start --><link rel="stylesheet" href="https://cdn.cbd.int/hexo-butterfly-clock-anzhiyu/lib/clock.min.css" /><!-- hexo injector head_end end --><meta name="generator" content="Hexo 6.2.0"></head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src= "" data-lazy-src="https://portrait.gitee.com/uploads/avatars/user/2982/8948190_JIAXInT_1624177607.png!avatar200" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">25</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">2</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">3</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fa fa-graduation-cap"></i><span> 博文</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/categories/"><i class="fa-fw fa fa-archive"></i><span> 分类</span></a></li><li><a class="site-page child" href="/tags/"><i class="fa-fw fa fa-tags"></i><span> 标签</span></a></li><li><a class="site-page child" href="/archives/"><i class="fa-fw fa fa-folder-open"></i><span> 归档</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/project/"><i class="fa-fw fas fa-images"></i><span> 项目</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fa fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/messageboard/"><i class="fa-fw fa fa-paper-plane"></i><span> 留言板</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于笔者</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://dogefs.s3.ladydaily.com/~/source/wallhaven/full/z8/wallhaven-z82evv.jpg')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">Justic</a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fa fa-graduation-cap"></i><span> 博文</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/categories/"><i class="fa-fw fa fa-archive"></i><span> 分类</span></a></li><li><a class="site-page child" href="/tags/"><i class="fa-fw fa fa-tags"></i><span> 标签</span></a></li><li><a class="site-page child" href="/archives/"><i class="fa-fw fa fa-folder-open"></i><span> 归档</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/project/"><i class="fa-fw fas fa-images"></i><span> 项目</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fa fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/messageboard/"><i class="fa-fw fa fa-paper-plane"></i><span> 留言板</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于笔者</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">深入JavaScript的运行原理</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2022-07-27T12:54:33.000Z" title="发表于 2022-07-27 20:54:33">2022-07-27</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2022-08-08T03:23:05.522Z" title="更新于 2022-08-08 11:23:05">2022-08-08</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/JavaScript/">JavaScript</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">1.5k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>5分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="深入JavaScript的运行原理"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span><span class="post-meta-separator">|</span><span class="post-meta-commentcount"><i class="far fa-comments fa-fw post-meta-icon"></i><span class="post-meta-label">评论数:</span><a href="/2022/07/27/JavaScript/%E6%B7%B1%E5%85%A5JavaScript%E7%9A%84%E8%BF%90%E8%A1%8C%E5%8E%9F%E7%90%86/index/#post-comment" itemprop="discussionUrl"><span class="valine-comment-count" data-xid="/2022/07/27/JavaScript/%E6%B7%B1%E5%85%A5JavaScript%E7%9A%84%E8%BF%90%E8%A1%8C%E5%8E%9F%E7%90%86/index/" itemprop="commentCount"><i class="fa-solid fa-spinner fa-spin"></i></span></a></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1 id="1、深入V8引擎原理"><a href="#1、深入V8引擎原理" class="headerlink" title="1、深入V8引擎原理"></a>1、深入V8引擎原理</h1><h2 id="1-1-JavaScript代码的执行"><a href="#1-1-JavaScript代码的执行" class="headerlink" title="1.1 JavaScript代码的执行"></a>1.1 JavaScript代码的执行</h2><p><strong>JavaScript代码下载好之后，是如何一步步被执行的呢？</strong></p>
<p><strong>我们知道，浏览器内核是由两部分组成的，以webkit为例：</strong></p>
<ul>
<li>WebCore：负责解析HTML解析、布局、渲染等等相关的工作</li>
<li>JavaScriptCore：解析、执行JavaScript代码</li>
</ul>
<p><img src= "" data-lazy-src="/2022/07/27/JavaScript/%E6%B7%B1%E5%85%A5JavaScript%E7%9A%84%E8%BF%90%E8%A1%8C%E5%8E%9F%E7%90%86/index/image-20220727205859360.png" alt="image-20220727205859360"></p>
<p><strong>另外一个强大的JavaScript引擎就是V8引擎</strong></p>
<h2 id="1-2-V8引擎的执行原理"><a href="#1-2-V8引擎的执行原理" class="headerlink" title="1.2 V8引擎的执行原理"></a>1.2 V8引擎的执行原理</h2><p> <strong>我们先来看一下官方对V8引擎的定义：</strong></p>
<ul>
<li>V8是用C ++编写的Google开源高性能JavaScript和WebAssembly引擎，它用于Chrome和Node.js等。</li>
<li>它实现ECMAScript和WebAssembly，并在Windows 7或更高版本，macOS 10.12+和使用x64，IA-32，ARM或MIPS处理器的Linux系统上运行。</li>
<li>V8可以独立运行，也可以嵌入到任何C ++应用程序中</li>
</ul>
<p><img src= "" data-lazy-src="/2022/07/27/JavaScript/%E6%B7%B1%E5%85%A5JavaScript%E7%9A%84%E8%BF%90%E8%A1%8C%E5%8E%9F%E7%90%86/index/image-20220727215523995.png" alt="image-20220727215523995"></p>
<h2 id="1-3-V8引擎的架构"><a href="#1-3-V8引擎的架构" class="headerlink" title="1.3 V8引擎的架构"></a>1.3 V8引擎的架构</h2><p><strong>V8引擎本身的源码非常复杂，大概有超过100w行C++代码，通过了解它的架构，我们可以知道它是如何对JavaScript执行的：</strong></p>
<p><strong>Parse模块会将JavaScript代码转换成AST（抽象语法树），这是因为解释器并不直接认识JavaScript代码；</strong></p>
<ul>
<li>如果函数没有被调用，那么是不会被转换成AST的；</li>
<li>Parse的V8官方文档：<a target="_blank" rel="noopener" href="https://v8.dev/blog/scanner">https://v8.dev/blog/scanner</a></li>
</ul>
<p><strong>Ignition是一个解释器，会将AST转换成ByteCode（字节码）</strong></p>
<ul>
<li>同时会收集TurboFan优化所需要的信息（比如函数参数的类型信息，有了类型才能进行真实的运算）</li>
<li>如果函数只调用一次，Ignition会解释执行ByteCode</li>
<li>Ignition的V8官方文档：<a target="_blank" rel="noopener" href="https://v8.dev/blog/ignition-interpreter">https://v8.dev/blog/ignition-interpreter</a></li>
</ul>
<p><strong>TurboFan是一个编译器，可以将字节码编译为CPU可以直接执行的机器码</strong></p>
<ul>
<li>如果一个函数被多次调用，那么就会被标记为热点函数，那么就会经过TurboFan转换成优化的机器码，提高代码的执行性能；</li>
<li>但是，机器码实际上也会被还原为ByteCode，这是因为如果后续执行函数的过程中，类型发生了变化（比如sum函数原来执行的是number类型，后来执行变成了string类型），之前优化的机器码并不能正确的处理运算，就会逆向的转换成字节码；</li>
<li>TurboFan的V8官方文档：<a target="_blank" rel="noopener" href="https://v8.dev/blog/turbofan-jit">https://v8.dev/blog/turbofan-jit</a></li>
</ul>
<h2 id="1-4-V8引擎的解析图（官方）"><a href="#1-4-V8引擎的解析图（官方）" class="headerlink" title="1.4 V8引擎的解析图（官方）"></a>1.4 V8引擎的解析图（官方）</h2><p><img src= "" data-lazy-src="/2022/07/27/JavaScript/%E6%B7%B1%E5%85%A5JavaScript%E7%9A%84%E8%BF%90%E8%A1%8C%E5%8E%9F%E7%90%86/index/image-20220727220031896.png" alt="image-20220727220031896"></p>
<p><strong>词法分析（英文lexical analysis）</strong></p>
<ul>
<li>将字符序列转换成token序列的过程</li>
<li>token是记号化（tokenization）的缩写</li>
<li>词法分析器（lexical analyzer，简称lexer），也叫扫描器（scanner）</li>
</ul>
<p><strong>语法分析（英语：syntactic analysis，也叫 parsing）</strong></p>
<ul>
<li>语法分析器也可以称之为parser。</li>
</ul>
<h2 id="1-5-V8引擎解析图"><a href="#1-5-V8引擎解析图" class="headerlink" title="1.5 V8引擎解析图"></a>1.5 V8引擎解析图</h2><p><img src= "" data-lazy-src="/2022/07/27/JavaScript/%E6%B7%B1%E5%85%A5JavaScript%E7%9A%84%E8%BF%90%E8%A1%8C%E5%8E%9F%E7%90%86/index/image-20220727220235819.png" alt="image-20220727220235819"></p>
<h1 id="2、JS执行上下文"><a href="#2、JS执行上下文" class="headerlink" title="2、JS执行上下文"></a>2、JS执行上下文</h1><h2 id="2-1-JavaScript的执行过程"><a href="#2-1-JavaScript的执行过程" class="headerlink" title="2.1 JavaScript的执行过程"></a>2.1 JavaScript的执行过程</h2><p><strong>假如我们有下面一段代码，它在JavaScript中是如何被执行的呢？</strong></p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> name = <span class="string">&quot;justic&quot;</span></span><br><span class="line"><span class="keyword">function</span> <span class="title function_">foo</span>(<span class="params"></span>) &#123;</span><br><span class="line">    <span class="keyword">var</span> name = <span class="string">&#x27;foo&#x27;</span></span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(name)</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> num1 = <span class="number">20</span></span><br><span class="line"><span class="keyword">var</span> num2 = <span class="number">30</span></span><br><span class="line"><span class="keyword">var</span> result = num1 + num2</span><br><span class="line"></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(result)</span><br><span class="line"></span><br><span class="line"><span class="title function_">foo</span>()</span><br></pre></td></tr></table></figure>

<h2 id="2-2-初始化全局对象"><a href="#2-2-初始化全局对象" class="headerlink" title="2.2 初始化全局对象"></a>2.2 初始化全局对象</h2><p><strong>js引擎会在代码执行之前，在堆内存中创建一个全局对象：Global Object（GO）</strong></p>
<ul>
<li>该对象 所有的作用域（scope）都可以访问</li>
<li>里面包含Date、Array、String、Number、setTimeout、setinterval等等；</li>
<li>其中还有一个window属性指向自己；</li>
</ul>
<p><img src= "" data-lazy-src="/2022/07/27/JavaScript/%E6%B7%B1%E5%85%A5JavaScript%E7%9A%84%E8%BF%90%E8%A1%8C%E5%8E%9F%E7%90%86/index/image-20220808102629126.png" alt="image-20220808102629126"></p>
<h2 id="2-3-执行上下文（Execution-Contexts）"><a href="#2-3-执行上下文（Execution-Contexts）" class="headerlink" title="2.3 执行上下文（Execution Contexts）"></a>2.3 执行上下文（Execution Contexts）</h2><p><strong>js引擎内部有一个执行上下文栈(Execution Context Stack，简称ECS），它是用于执行代码的调用栈</strong></p>
<p><strong>那么现在它要执行谁呢？执行的是全局的代码块</strong></p>
<ul>
<li>全局的代码块为了执行会构建一个Global Execution Context（GEC）</li>
<li>全局执行上下文（GEC）会被放入到执行上下文栈（ECS）中执行</li>
</ul>
<p><strong>全局执行上下文被放入到执行上下文栈中里面包含两部分内容</strong>：</p>
<ul>
<li><strong>第一部分</strong>：在代码执行前，在parse转成AST的过程中，会将全局定义的变量、函数等加入到GlobalObject中，但是并不会赋值；这过程也称之为变量的作用域提升（hoising）</li>
<li><strong>第二部分</strong>：在代码执行中，对变量赋值，或者执行其他的函数；</li>
</ul>
<p><img src= "" data-lazy-src="/2022/07/27/JavaScript/%E6%B7%B1%E5%85%A5JavaScript%E7%9A%84%E8%BF%90%E8%A1%8C%E5%8E%9F%E7%90%86/index/image-20220808103253872.png" alt="image-20220808103253872"></p>
<h2 id="2-4-认识VO对象（Variable-Object）"><a href="#2-4-认识VO对象（Variable-Object）" class="headerlink" title="2.4 认识VO对象（Variable Object）"></a>2.4 认识VO对象（Variable Object）</h2><p><strong>每一个执行上下文会关联一个VO（Variable Object，变量对象），变量和函数声明会被添加到这个VO对象中。</strong></p>
<p><img src= "" data-lazy-src="/2022/07/27/JavaScript/%E6%B7%B1%E5%85%A5JavaScript%E7%9A%84%E8%BF%90%E8%A1%8C%E5%8E%9F%E7%90%86/index/image-20220808103447204.png" alt="image-20220808103447204"></p>
<p><strong>当全局代码被执行的时候，VO就是GO对象了</strong></p>
<p><img src= "" data-lazy-src="/2022/07/27/JavaScript/%E6%B7%B1%E5%85%A5JavaScript%E7%9A%84%E8%BF%90%E8%A1%8C%E5%8E%9F%E7%90%86/index/image-20220808103520250.png" alt="image-20220808103520250"></p>
<h1 id="3、全局代码执行过程"><a href="#3、全局代码执行过程" class="headerlink" title="3、全局代码执行过程"></a>3、全局代码执行过程</h1><h2 id="3-1-全局代码执行过程（执行前）"><a href="#3-1-全局代码执行过程（执行前）" class="headerlink" title="3.1 全局代码执行过程（执行前）"></a>3.1 全局代码执行过程（执行前）</h2><p><img src= "" data-lazy-src="/2022/07/27/JavaScript/%E6%B7%B1%E5%85%A5JavaScript%E7%9A%84%E8%BF%90%E8%A1%8C%E5%8E%9F%E7%90%86/index/image-20220808103609081.png" alt="image-20220808103609081"></p>
<h2 id="3-2-全局代码执行过程（执行后）"><a href="#3-2-全局代码执行过程（执行后）" class="headerlink" title="3.2 全局代码执行过程（执行后）"></a>3.2 全局代码执行过程（执行后）</h2><p><img src= "" data-lazy-src="/2022/07/27/JavaScript/%E6%B7%B1%E5%85%A5JavaScript%E7%9A%84%E8%BF%90%E8%A1%8C%E5%8E%9F%E7%90%86/index/image-20220808103658382.png" alt="image-20220808103658382"></p>
<h1 id="4、函数代码执行过程"><a href="#4、函数代码执行过程" class="headerlink" title="4、函数代码执行过程"></a>4、函数代码执行过程</h1><h2 id="4-1-函数如何被执行呢？"><a href="#4-1-函数如何被执行呢？" class="headerlink" title="4.1 函数如何被执行呢？"></a>4.1 函数如何被执行呢？</h2><p><strong>在执行的过程中执行到一个函数时，就会根据函数体创建一个函数执行上下文（Function Execution Context，简称FEC），并且压入到EC Stack汇总</strong></p>
<p><strong>因为每个执行上下文都会关联一个VO，那么函数执行上下文关联的VO是什么呢？</strong></p>
<ul>
<li>当然进入一个函数执行上下文时，会创建一个AO对象（Activation Object）；</li>
<li>这个AO对象会使用arguments作为初始化，并且初始值是传入的参数；</li>
<li>这个AO对象会作为执行上下文的VO来存放变量的初始化；</li>
</ul>
<p><img src= "" data-lazy-src="/2022/07/27/JavaScript/%E6%B7%B1%E5%85%A5JavaScript%E7%9A%84%E8%BF%90%E8%A1%8C%E5%8E%9F%E7%90%86/index/image-20220808104103043.png" alt="image-20220808104103043"></p>
<h2 id="4-2-函数的执行过程（执行前）"><a href="#4-2-函数的执行过程（执行前）" class="headerlink" title="4.2 函数的执行过程（执行前）"></a>4.2 函数的执行过程（执行前）</h2><p><img src= "" data-lazy-src="/2022/07/27/JavaScript/%E6%B7%B1%E5%85%A5JavaScript%E7%9A%84%E8%BF%90%E8%A1%8C%E5%8E%9F%E7%90%86/index/image-20220808104132087.png" alt="image-20220808104132087"></p>
<h2 id="4-3-函数的执行过程（执行后）"><a href="#4-3-函数的执行过程（执行后）" class="headerlink" title="4.3 函数的执行过程（执行后）"></a>4.3 函数的执行过程（执行后）</h2><p><img src= "" data-lazy-src="/2022/07/27/JavaScript/%E6%B7%B1%E5%85%A5JavaScript%E7%9A%84%E8%BF%90%E8%A1%8C%E5%8E%9F%E7%90%86/index/image-20220808104211503.png" alt="image-20220808104211503"></p>
<h1 id="5、作用域和作用域链"><a href="#5、作用域和作用域链" class="headerlink" title="5、作用域和作用域链"></a>5、作用域和作用域链</h1><h2 id="5-1-作用域和作用域链（Scope-Chain）"><a href="#5-1-作用域和作用域链（Scope-Chain）" class="headerlink" title="5.1 作用域和作用域链（Scope Chain）"></a>5.1 作用域和作用域链（Scope Chain）</h2><p><strong>当进入到一个执行上下文时，执行上下文也会关联一个作用域链（Scope Chain）</strong></p>
<ul>
<li>作用域链是一个对象列表，用于变量标识符的求值</li>
<li>当进入一个执行上下文时，这个作用域链被创建，并且根据代码类型，添加一系列的对象；</li>
</ul>
<p><img src= "" data-lazy-src="/2022/07/27/JavaScript/%E6%B7%B1%E5%85%A5JavaScript%E7%9A%84%E8%BF%90%E8%A1%8C%E5%8E%9F%E7%90%86/index/image-20220808104913369.png" alt="image-20220808104913369"></p>
<h2 id="5-2-作用域提升面试题"><a href="#5-2-作用域提升面试题" class="headerlink" title="5.2 作用域提升面试题"></a>5.2 作用域提升面试题</h2><figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="comment">// 1.面试题一:</span></span><br><span class="line"><span class="keyword">var</span> n = <span class="number">100</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">function</span> <span class="title function_">foo</span>(<span class="params"></span>) &#123;</span><br><span class="line">    n = <span class="number">200</span>;</span><br><span class="line">&#125;</span><br><span class="line"><span class="title function_">foo</span>();</span><br><span class="line"></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(n); <span class="comment">// 200</span></span><br></pre></td></tr></table></figure>

<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="comment">// 2.面试题二:</span></span><br><span class="line"><span class="keyword">var</span> n = <span class="number">100</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">function</span> <span class="title function_">foo</span>(<span class="params"></span>) &#123;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(n);</span><br><span class="line">    <span class="keyword">var</span> n = <span class="number">200</span>;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(n);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="title function_">foo</span>();<span class="comment">// undefined 200</span></span><br></pre></td></tr></table></figure>

<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="comment">// 3.面试题三:</span></span><br><span class="line"><span class="keyword">var</span> n = <span class="number">100</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">function</span> <span class="title function_">foo1</span>(<span class="params"></span>) &#123;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(n);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">function</span> <span class="title function_">foo2</span>(<span class="params"></span>) &#123;</span><br><span class="line">    <span class="keyword">var</span> n = <span class="number">200</span>;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(n);</span><br><span class="line">    <span class="title function_">foo1</span>();</span><br><span class="line">&#125;</span><br><span class="line"><span class="title function_">foo2</span>(); <span class="comment">// 200 100</span></span><br></pre></td></tr></table></figure>

<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="comment">// 4.面试题四:</span></span><br><span class="line"><span class="keyword">var</span> n = <span class="number">100</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">function</span> <span class="title function_">foo</span>(<span class="params"></span>) &#123;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(n);</span><br><span class="line">    <span class="keyword">return</span>;</span><br><span class="line">    <span class="keyword">var</span> n = <span class="number">200</span>;</span><br><span class="line">&#125;</span><br><span class="line"><span class="title function_">foo</span>(); <span class="comment">// undefined</span></span><br></pre></td></tr></table></figure>

<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="comment">// 6.面试题五:</span></span><br><span class="line"><span class="keyword">function</span> <span class="title function_">foo</span>(<span class="params"></span>) &#123;</span><br><span class="line">    <span class="comment">//会在全局作用域中创建变量b</span></span><br><span class="line">    <span class="keyword">var</span> a = (b = <span class="number">100</span>);</span><br><span class="line">&#125;</span><br><span class="line"><span class="title function_">foo</span>();</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(b); <span class="comment">//100</span></span><br></pre></td></tr></table></figure>

</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="http://example.com">Justic</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="http://example.com/2022/07/27/JavaScript/%E6%B7%B1%E5%85%A5JavaScript%E7%9A%84%E8%BF%90%E8%A1%8C%E5%8E%9F%E7%90%86/index/">http://example.com/2022/07/27/JavaScript/深入JavaScript的运行原理/index/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://justicc.top/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="http://example.com" target="_blank">Justic</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/JavaScript/">JavaScript</a></div><div class="post_share"><div class="social-share" data-image="https://dogefs.s3.ladydaily.com/~/source/wallhaven/full/z8/wallhaven-z82evv.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><div class="post-reward"><div class="reward-button"><i class="fas fa-qrcode"></i> 打赏</div><div class="reward-main"><ul class="reward-all"><li class="reward-item"><a href="/img/wechat.jpg" target="_blank"><img class="post-qr-code-img" src= "" data-lazy-src="/img/wechat.jpg" alt="微信"/></a><div class="post-qr-code-desc">微信</div></li><li class="reward-item"><a href="/img/alipay.jpg" target="_blank"><img class="post-qr-code-img" src= "" data-lazy-src="/img/alipay.jpg" alt="支付宝"/></a><div class="post-qr-code-desc">支付宝</div></li></ul></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/2022/08/08/JavaScript/JavaScript%E5%87%BD%E6%95%B0%E5%A2%9E%E5%BC%BA%E7%9F%A5%E8%AF%86/index/"><img class="prev-cover" src= "" data-lazy-src="https://dogefs.s3.ladydaily.com/~/source/wallhaven/full/28/wallhaven-2881yx.png" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">JavaScript函数增强知识</div></div></a></div><div class="next-post pull-right"><a href="/2022/07/26/JavaScript/%E6%B7%B1%E5%85%A5%E6%B5%8F%E8%A7%88%E5%99%A8%E7%9A%84%E6%B8%B2%E6%9F%93%E5%8E%9F%E7%90%86/index/"><img class="next-cover" src= "" data-lazy-src="https://dogefs.s3.ladydaily.com/~/source/wallhaven/full/z8/wallhaven-z82evv.jpg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">深入浏览器的渲染原理</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><div><a href="/2022/07/07/JavaScript/JavaScript%E5%BC%95%E6%93%8E/" title="JavaScript 引擎"><img class="cover" src= "" data-lazy-src="https://pic1.zhimg.com/v2-4dce785ff4595de55623611ab0055d33_1440w.jpg?source=172ae18b" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-07-07</div><div class="title">JavaScript 引擎</div></div></a></div><div><a href="/2022/07/22/JavaScript/JavaScript%E5%87%BD%E6%95%B0this%E6%8C%87%E5%90%91/JavaScript%E5%87%BD%E6%95%B0this%E6%8C%87%E5%90%91/" title="JavaScript函数this指向"><img class="cover" src= "" data-lazy-src="https://dogefs.s3.ladydaily.com/~/source/wallhaven/full/k7/wallhaven-k7jmg6.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-07-22</div><div class="title">JavaScript函数this指向</div></div></a></div><div><a href="/2022/07/13/JavaScript/JavaScript%20%E9%9D%A2%E8%AF%95%E7%B2%BE%E8%AE%B2/JavaScript%E6%80%A7%E8%83%BD%E4%BC%98%E5%8C%96/" title="JavaScript 性能优化"><img class="cover" src= "" data-lazy-src="https://dogefs.s3.ladydaily.com/~/source/wallhaven/full/3z/wallhaven-3zgz2y.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-07-13</div><div class="title">JavaScript 性能优化</div></div></a></div><div><a href="/2022/07/13/JavaScript/JavaScript%20%E9%9D%A2%E8%AF%95%E7%B2%BE%E8%AE%B2/JavaScript%E5%BC%82%E6%AD%A5%E7%BC%96%E7%A8%8B/" title="JavaScript 异步编程"><img class="cover" src= "" data-lazy-src="https://dogefs.s3.ladydaily.com/~/source/wallhaven/full/j3/wallhaven-j3qq15.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-07-13</div><div class="title">JavaScript 异步编程</div></div></a></div><div><a href="/2022/07/13/JavaScript/JavaScript%20%E9%9D%A2%E8%AF%95%E7%B2%BE%E8%AE%B2/%E6%A8%A1%E5%9D%97%E5%8C%96/" title="JavaScript 模块化"><img class="cover" src= "" data-lazy-src="https://dogefs.s3.ladydaily.com/~/source/wallhaven/full/m9/wallhaven-m9y289.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-07-13</div><div class="title">JavaScript 模块化</div></div></a></div><div><a href="/2022/08/08/JavaScript/JavaScript%E5%87%BD%E6%95%B0%E5%A2%9E%E5%BC%BA%E7%9F%A5%E8%AF%86/index/" title="JavaScript函数增强知识"><img class="cover" src= "" data-lazy-src="https://dogefs.s3.ladydaily.com/~/source/wallhaven/full/28/wallhaven-2881yx.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-08-08</div><div class="title">JavaScript函数增强知识</div></div></a></div></div></div><hr/><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="fas fa-comments fa-fw"></i><span> 评论</span></div></div><div class="comment-wrap"><div><div class="vcomment" id="vcomment"></div></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src= "" data-lazy-src="https://portrait.gitee.com/uploads/avatars/user/2982/8948190_JIAXInT_1624177607.png!avatar200" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">Justic</div><div class="author-info__description">最是人间留不住 朱颜辞镜花辞树</div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">25</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">2</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">3</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/xxxxxx"><i class="fab fa-github"></i><span>Follow Me</span></a></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">This is my Blog</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#1%E3%80%81%E6%B7%B1%E5%85%A5V8%E5%BC%95%E6%93%8E%E5%8E%9F%E7%90%86"><span class="toc-text">1、深入V8引擎原理</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#1-1-JavaScript%E4%BB%A3%E7%A0%81%E7%9A%84%E6%89%A7%E8%A1%8C"><span class="toc-text">1.1 JavaScript代码的执行</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#1-2-V8%E5%BC%95%E6%93%8E%E7%9A%84%E6%89%A7%E8%A1%8C%E5%8E%9F%E7%90%86"><span class="toc-text">1.2 V8引擎的执行原理</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#1-3-V8%E5%BC%95%E6%93%8E%E7%9A%84%E6%9E%B6%E6%9E%84"><span class="toc-text">1.3 V8引擎的架构</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#1-4-V8%E5%BC%95%E6%93%8E%E7%9A%84%E8%A7%A3%E6%9E%90%E5%9B%BE%EF%BC%88%E5%AE%98%E6%96%B9%EF%BC%89"><span class="toc-text">1.4 V8引擎的解析图（官方）</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#1-5-V8%E5%BC%95%E6%93%8E%E8%A7%A3%E6%9E%90%E5%9B%BE"><span class="toc-text">1.5 V8引擎解析图</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#2%E3%80%81JS%E6%89%A7%E8%A1%8C%E4%B8%8A%E4%B8%8B%E6%96%87"><span class="toc-text">2、JS执行上下文</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#2-1-JavaScript%E7%9A%84%E6%89%A7%E8%A1%8C%E8%BF%87%E7%A8%8B"><span class="toc-text">2.1 JavaScript的执行过程</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-2-%E5%88%9D%E5%A7%8B%E5%8C%96%E5%85%A8%E5%B1%80%E5%AF%B9%E8%B1%A1"><span class="toc-text">2.2 初始化全局对象</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-3-%E6%89%A7%E8%A1%8C%E4%B8%8A%E4%B8%8B%E6%96%87%EF%BC%88Execution-Contexts%EF%BC%89"><span class="toc-text">2.3 执行上下文（Execution Contexts）</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-4-%E8%AE%A4%E8%AF%86VO%E5%AF%B9%E8%B1%A1%EF%BC%88Variable-Object%EF%BC%89"><span class="toc-text">2.4 认识VO对象（Variable Object）</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#3%E3%80%81%E5%85%A8%E5%B1%80%E4%BB%A3%E7%A0%81%E6%89%A7%E8%A1%8C%E8%BF%87%E7%A8%8B"><span class="toc-text">3、全局代码执行过程</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#3-1-%E5%85%A8%E5%B1%80%E4%BB%A3%E7%A0%81%E6%89%A7%E8%A1%8C%E8%BF%87%E7%A8%8B%EF%BC%88%E6%89%A7%E8%A1%8C%E5%89%8D%EF%BC%89"><span class="toc-text">3.1 全局代码执行过程（执行前）</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3-2-%E5%85%A8%E5%B1%80%E4%BB%A3%E7%A0%81%E6%89%A7%E8%A1%8C%E8%BF%87%E7%A8%8B%EF%BC%88%E6%89%A7%E8%A1%8C%E5%90%8E%EF%BC%89"><span class="toc-text">3.2 全局代码执行过程（执行后）</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#4%E3%80%81%E5%87%BD%E6%95%B0%E4%BB%A3%E7%A0%81%E6%89%A7%E8%A1%8C%E8%BF%87%E7%A8%8B"><span class="toc-text">4、函数代码执行过程</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#4-1-%E5%87%BD%E6%95%B0%E5%A6%82%E4%BD%95%E8%A2%AB%E6%89%A7%E8%A1%8C%E5%91%A2%EF%BC%9F"><span class="toc-text">4.1 函数如何被执行呢？</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#4-2-%E5%87%BD%E6%95%B0%E7%9A%84%E6%89%A7%E8%A1%8C%E8%BF%87%E7%A8%8B%EF%BC%88%E6%89%A7%E8%A1%8C%E5%89%8D%EF%BC%89"><span class="toc-text">4.2 函数的执行过程（执行前）</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#4-3-%E5%87%BD%E6%95%B0%E7%9A%84%E6%89%A7%E8%A1%8C%E8%BF%87%E7%A8%8B%EF%BC%88%E6%89%A7%E8%A1%8C%E5%90%8E%EF%BC%89"><span class="toc-text">4.3 函数的执行过程（执行后）</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#5%E3%80%81%E4%BD%9C%E7%94%A8%E5%9F%9F%E5%92%8C%E4%BD%9C%E7%94%A8%E5%9F%9F%E9%93%BE"><span class="toc-text">5、作用域和作用域链</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#5-1-%E4%BD%9C%E7%94%A8%E5%9F%9F%E5%92%8C%E4%BD%9C%E7%94%A8%E5%9F%9F%E9%93%BE%EF%BC%88Scope-Chain%EF%BC%89"><span class="toc-text">5.1 作用域和作用域链（Scope Chain）</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#5-2-%E4%BD%9C%E7%94%A8%E5%9F%9F%E6%8F%90%E5%8D%87%E9%9D%A2%E8%AF%95%E9%A2%98"><span class="toc-text">5.2 作用域提升面试题</span></a></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/2022/11/09/JavaScript/ES6%E6%96%B0%E7%89%B9%E6%80%A7/index/" title="ES6新特性"><img src= "" data-lazy-src="https://dogefs.s3.ladydaily.com/~/source/wallhaven/full/m9/wallhaven-m9y289.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="ES6新特性"/></a><div class="content"><a class="title" href="/2022/11/09/JavaScript/ES6%E6%96%B0%E7%89%B9%E6%80%A7/index/" title="ES6新特性">ES6新特性</a><time datetime="2022-11-09T12:55:33.000Z" title="发表于 2022-11-09 20:55:33">2022-11-09</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2022/11/09/123/" title="123"><img src= "" data-lazy-src="https://dogefs.s3.ladydaily.com/~/source/wallhaven/full/z8/wallhaven-z82evv.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="123"/></a><div class="content"><a class="title" href="/2022/11/09/123/" title="123">123</a><time datetime="2022-11-09T12:40:11.000Z" title="发表于 2022-11-09 20:40:11">2022-11-09</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2022/11/09/ES6%E6%96%B0%E7%89%B9%E6%80%A7-1/" title="ES6新特性"><img src= "" data-lazy-src="https://dogefs.s3.ladydaily.com/~/source/wallhaven/full/z8/wallhaven-z82evv.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="ES6新特性"/></a><div class="content"><a class="title" href="/2022/11/09/ES6%E6%96%B0%E7%89%B9%E6%80%A7-1/" title="ES6新特性">ES6新特性</a><time datetime="2022-11-09T12:38:06.000Z" title="发表于 2022-11-09 20:38:06">2022-11-09</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2022/11/09/ES6%E6%96%B0%E7%89%B9%E6%80%A7/" title="ES6新特性"><img src= "" data-lazy-src="https://dogefs.s3.ladydaily.com/~/source/wallhaven/full/j3/wallhaven-j3qq15.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="ES6新特性"/></a><div class="content"><a class="title" href="/2022/11/09/ES6%E6%96%B0%E7%89%B9%E6%80%A7/" title="ES6新特性">ES6新特性</a><time datetime="2022-11-09T12:35:33.000Z" title="发表于 2022-11-09 20:35:33">2022-11-09</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2022/10/20/Vue/Vue%20%E5%93%8D%E5%BA%94%E5%BC%8F%E8%A7%A3%E6%9E%90/Vue%E5%93%8D%E5%BA%94%E5%BC%8F%E8%A7%A3%E6%9E%90/" title="Vue 响应式解析"><img src= "" data-lazy-src="https://dogefs.s3.ladydaily.com/~/source/wallhaven/full/z8/wallhaven-z82evv.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Vue 响应式解析"/></a><div class="content"><a class="title" href="/2022/10/20/Vue/Vue%20%E5%93%8D%E5%BA%94%E5%BC%8F%E8%A7%A3%E6%9E%90/Vue%E5%93%8D%E5%BA%94%E5%BC%8F%E8%A7%A3%E6%9E%90/" title="Vue 响应式解析">Vue 响应式解析</a><time datetime="2022-10-20T12:05:37.000Z" title="发表于 2022-10-20 20:05:37">2022-10-20</time></div></div></div></div></div></div></main><footer id="footer" style="background-image: url('https://dogefs.s3.ladydaily.com/~/source/wallhaven/full/z8/wallhaven-z82evv.jpg')"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2022 By Justic</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a><img src= "" data-lazy-src="https://static.dy208.cn/o_1dfilp8ruo521thr1hvf18ji17soa.png">
<a href="http://www.beian.miit.gov.cn/"  style="color:#f72b07" target="_blank">晋ICP备2021014440号-2</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="chat_btn" type="button" title="聊天"><i class="fas fa-sms"></i></button><a id="to_comment" href="#post-comment" title="直达评论"><i class="fas fa-comments"></i></a><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div id="local-search-results"></div></div></div><div id="search-mask"></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.min.js"></script><script src="https://cdn.jsdelivr.net/npm/vanilla-lazyload/dist/lazyload.iife.min.js"></script><script src="/js/search/local-search.js"></script><div class="js-pjax"><script>function loadValine () {
  function initValine () {
    const valine = new Valine(Object.assign({
      el: '#vcomment',
      appId: 'KgIigedIwh0GobYsWWfPMEdO-gzGzoHsz',
      appKey: 'WpJEQP22asTau19i2tq1yQhU',
      avatar: 'justic',
      serverURLs: '',
      emojiMaps: "",
      path: window.location.pathname,
      visitor: false
    }, null))
  }

  if (typeof Valine === 'function') initValine() 
  else getScript('https://cdn.jsdelivr.net/npm/valine/dist/Valine.min.js').then(initValine)
}

if ('Valine' === 'Valine' || !false) {
  if (false) btf.loadComment(document.getElementById('vcomment'),loadValine)
  else setTimeout(loadValine, 0)
} else {
  function loadOtherComment () {
    loadValine()
  }
}</script></div><div class="aplayer no-destroy" data-id="5076309057" data-server="netease" data-type="playlist" data-fixed="true" data-autoplay="true" data-lrcType="-1"> </div><script id="canvas_nest" defer="defer" color="0,0,255" opacity="0.7" zIndex="-1" count="99" mobile="false" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/canvas-nest.min.js"></script><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/activate-power-mode.min.js"></script><script>POWERMODE.colorful = true;
POWERMODE.shake = false;
POWERMODE.mobile = true;
document.body.addEventListener('input', POWERMODE);
</script><script id="click-show-text" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/click-show-text.min.js" data-mobile="true" data-text="富强,民主,文明,和谐,平等,公正,法治,爱国,敬业,诚信,友善" data-fontsize="15px" data-random="true" async="async"></script><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.js"></script><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/metingjs/dist/Meting.min.js"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><!-- hexo injector body_end start --><script data-pjax>
  function butterfly_clock_anzhiyu_injector_config(){
    var parent_div_git = document.getElementsByClassName('sticky_layout')[0];
    var item_html = '<div class="card-widget card-clock"><div class="card-glass"><div class="card-background"><div class="card-content"><div id="hexo_electric_clock"><img class="entered loading" id="card-clock-loading" src= "" data-lazy-src="https://cdn.cbd.int/hexo-butterfly-clock-anzhiyu/lib/loading.gif" style="height: 120px; width: 100%;" data-ll-status="loading"/></div></div></div></div></div>';
    console.log('已挂载butterfly_clock_anzhiyu')
    parent_div_git.insertAdjacentHTML("afterbegin",item_html)
    }
  var elist = 'null'.split(',');
  var cpage = location.pathname;
  var epage = 'all';
  var qweather_key = 'f854dfdd82d747fca7fd04f092861e87';
  var gaud_map_key = '427416c518f4476a01117be40057a892';
  var baidu_ak_key = 'undefined';
  var flag = 0;
  var clock_rectangle = '112.982279,28.19409';
  var clock_default_rectangle_enable = 'false';

  for (var i=0;i<elist.length;i++){
    if (cpage.includes(elist[i])){
      flag++;
    }
  }

  if ((epage ==='all')&&(flag == 0)){
    butterfly_clock_anzhiyu_injector_config();
  }
  else if (epage === cpage){
    butterfly_clock_anzhiyu_injector_config();
  }
  </script><script src="https://widget.qweather.net/simple/static/js/he-simple-common.js?v=2.0"></script><script data-pjax src="https://cdn.cbd.int/hexo-butterfly-clock-anzhiyu/lib/clock.min.js"></script><!-- hexo injector body_end end --></body></html>